{extend name="public/base" /} {block name="content"}

<div class="page">
    <div class="page__hd profile">
        <img src="{$game.picture}" alt="">
        <p>{$game.name}'s game({$game.num} man {$game.amount} dollors)</p>
    </div>
    <div class="page__bd">
        <div class="weui-btn-area">
            {if condition="!$joined"}
            <a href="javascript:;" class="weui-btn weui-btn_plain-primary join-btn">Join</a>
            {/if}
        </div>
        <div class="weui-cells__title">player list</div>
        <div class="weui-cells player-list">
            {foreach $player_list as $player}
                <div class="weui-cell">
                    <div class="weui-cell__hd"><img src="{$player.picture}"></div>
                    <div class="weui-cell__bd">
                        <p>{$player.name}</p>
                    </div>
                    <div class="weui-cell__ft">${$game.amount}</div>
                </div>
            {/foreach}
        </div>
    </div>
</div>


{/block}

{block name="script"}
<script>
    $(function(){
        $('.join-btn').on('click', function(){
            $.ajax({
                type: 'post',
                url: "{:url('index/joinHandler')}",
                data: {
                    game_id: {$Request.param.id}
                },
                success: function(res){
                    if(res.err){
                        $.alert(res.msg, 'hint')
                    }else{
                        if(res.data == 'joined'){
                            $.alert(res.msg, 'hint')
                        }else{
                            location.href = "{:url('index/award', ['id' => $Request.param.id])}"
                        }
                    }
                }
            })
        })
    })
</script>
{/block}